function GetUrlRelativePath() {
	var url = window.location.href;
	var urlArray = url.split("/");
	return urlArray[urlArray.length - 1].split("?")[0];
}

function exit() {
	localStorage.removeItem('wallet_token');
	window.location.href="login.html";
	
}
var header =
	'<header class="main-header">\
    	<nav class="navbar navbar-static-top">\
      	<a href="javascript:;" class="sidebar-toggle" data-toggle="push-menu" role="button">\
        <span class="sr-only">Toggle navigation</span>\
      	</a>\
      	<div class="navbar-custom-menu">\
        <ul class="nav navbar-nav">\
        <li class="dropdown user user-menu">\
		<a href=" " class="dropdown-toggle" data-toggle="dropdown">\
		<img src="dist/img/user2-160x160.jpg" class="user-image" alt="User Image">\
		<span class="hidden-xs manager-name">' + localStorage.getItem('wallet_name') + '</span>\
		</a>\
		<ul class="dropdown-menu">\
		<li class="user-header">\
		<img src="dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">\
		<p class="manager-name">' + localStorage.getItem('wallet_name') + '</p>\
		</li>\
		<li class="user-footer">\
		<div class="pull-right">\
		<a href="#" class="btn btn-default btn-flat" onclick="exit()">退出登录</a>\
		</div>\
		</li>\
		</ul>\
		</li>\
        </ul>\
      	</div>\
    	</nav>\
  	</header>';
$(".wrapper").prepend(header);

var menuData = JSON.parse(localStorage.getItem("wallet_menu"));
console.log(menuData)
var str = '<aside class="main-sidebar"><section class="sidebar"><img src="img/Glogo.png" style="display:block;width:35%;margin:40px auto 20px;z-index:1030;"><ul class="sidebar-menu" data-widget="tree">';
var homeStr='',otherStr='',
	iconChar = {
		1:"fa-bar-chart",
		10:"fa-user",
		100:"fa-paperclip",
		200:"fa-gamepad",
		250:'fa-dashboard',
		300:"fa-cog",
		400:"fa-money",
		500:"fa-ambulance",
		600:"fa-print"
	};
for(var i = 0; i < menuData.length; i++) {
if(menuData[i]){
	if(menuData[i].pid == 0) {	
		if(!menuData[i].web_url){
			homeStr+='<li class="treeview" code="'+menuData[i].id+'"><a href="#"><i class="fa '+iconChar[menuData[i].id]+'"></i><span>' + menuData[i].auth_name + '</span><span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i> </span> </a><ul class="treeview-menu"></ul></li>'
		}else{
			homeStr+='<li  code="'+menuData[i].id+'"><a href="'+menuData[i].web_url+'"><i class="fa '+iconChar[menuData[i].id]+'"></i><span>' + menuData[i].auth_name + '</span><span class="pull-right-container"> </span> </a><ul class="treeview-menu"></ul></li>'
		}
	}
}
}
str += homeStr + otherStr + '</ul></section></aside>';
$(".wrapper").prepend(str);

for(var i = 0; i < menuData.length; i++) {
	if(menuData[i]){
		if(menuData[i].pid != 0) {
			var active = "";
			menuData[i].web_url == GetUrlRelativePath() ? (active = "active") : (active = "");
			var sonStr = '<li class="' + active + ' li"><a href="' + menuData[i].web_url + '" pageId="' + menuData[i].id + '">' + menuData[i].auth_name + '</a></li>';
			$(".sidebar-menu [code = "+menuData[i].pid+"]").eq(0).find("ul").append(sonStr);
		}
	}
}


$(".li.active").parents(".treeview").addClass("menu-open active")

if($("#dataTable").length > 0) {
	$.fn.dataTable.ext.errMode = 'none';
}